package com.hzeport.bgs22emduty.inbound.api;

import com.hzeport.bgs22emduty.config.login.LoginCompoentService;
import com.hzeport.bgs22emduty.config.login.UserInfoDetailVO;
import com.hzeport.bgs22emduty.dto.duty.BasePersonInfoInitVO;
import com.hzeport.bgs22emduty.dto.duty.DutyPersonInitDetailVO;
import com.hzeport.bgs22emduty.dto.duty.DutyPersonInitVO;
import com.hzeport.bgs22emduty.dto.duty.DutyScheduleInitPersonForDetailDTO;
import com.hzeport.bgs22emduty.entity.BaseDeptInfo;
import com.hzeport.bgs22emduty.entity.BasePersonInfo;
import com.hzeport.bgs22emduty.service.BaseDeptInfoService;
import com.hzeport.bgs22emduty.vo.dudyScheduleSet.DudyScheduleInitVO;
import com.hzeport.bgs22emduty.common.base.BaseResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//////import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * @author hzeport
 */
@RestController
@AllArgsConstructor
@RequestMapping("/basedeptinfo")
@Api(value = "basedeptinfo", tags = "部门管理")
@Slf4j
public class BaseDeptInfoController {

    private final BaseDeptInfoService baseDeptInfoService;

    private final LoginCompoentService loginCompoentService;
    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区列表查询", notes = "关区列表")
    @GetMapping("/customsList")
    public BaseResult customsList() {
        UserInfoDetailVO userInfoDetailVO=loginCompoentService.getUserInfo();
        return BaseResult.ok(baseDeptInfoService.neoCustomList(userInfoDetailVO));
    }

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区列表查询", notes = "关区列表")
    @GetMapping("/customsListZG")
    public BaseResult customsListZG() {
        return BaseResult.ok(baseDeptInfoService.customsListZG());
    }

    @ApiOperation(value = "关区列表查询全部", notes = "关区列表查询全部")
    @GetMapping("/customsListAll")
    public BaseResult customsListAll() {
        UserInfoDetailVO userInfoDetailVO=loginCompoentService.getUserInfo();
        return BaseResult.ok(baseDeptInfoService.customsListAll(userInfoDetailVO));
    }

    @ApiOperation(value = "关区列表查询-无需权限", notes = "关区列表查询-无需权限")
    @GetMapping("/customsListWithOutPermission")
    public BaseResult customsListWithOutPermission() {
        return BaseResult.ok(baseDeptInfoService.customsListWithOutPermission());
    }

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区下部门列表查询", notes = "关区列表")
    @GetMapping("/deptSList")
    public BaseResult deptSList(@RequestParam("customId") String customId) {
        return BaseResult.ok(baseDeptInfoService.deptSList(customId));
    }

    @ApiOperation( value = "部门树", notes = "部门树" )
    @GetMapping( "/deptTree" )
    public BaseResult deptTree(@RequestParam("customId")String customId) {
        return baseDeptInfoService.deptTree(customId);
    }

    @ApiOperation( value = "部门树-总署特供", notes = "部门树-总署特供" )
    @GetMapping( "/deptTreeZS" )
    public BaseResult deptTreeZS(@RequestParam("customId")String customId) {
        return baseDeptInfoService.deptTreeZS(customId);
    }
//
//    /**
//     * 分页查询
//     * @return
//     */
//    @ApiOperation(value = "关区下一级部门列表查询", notes = "关区列表")
//    @GetMapping("/oneLevleList")
//    public BaseResult oneLevleList(@RequestParam("customId") String customId) {
//        return BaseResult.ok(baseDeptInfoService.oneLevleList(customId));
//    }

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区下部门列表查询", notes = "关区列表")
    @GetMapping("/subCustomsList")
    public BaseResult subCustomsList(@RequestParam("customId") String customId) {
        return BaseResult.ok(baseDeptInfoService.subCustomsList(customId));
    }

    @ApiOperation(value = "值班查询页面部门下拉框", notes = "下拉框列表")
    @GetMapping("/selectdeptSList")
    public BaseResult<List<BaseDeptInfo>> selectdeptSList(@RequestParam("customId") String customId) {
        return BaseResult.ok(baseDeptInfoService.selectdeptSList(customId));
    }
    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化", notes = "排班分配初始化")
    @PostMapping("/dutyScheduleInit")
    public BaseResult dutyScheduleInit(@RequestBody DudyScheduleInitVO dudyScheduleInitVO) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInit(dudyScheduleInitVO));
    }

    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化", notes = "排班分配初始化")
    @PostMapping("/dutyScheduleInitZS")
    public BaseResult dutyScheduleInitZS(@RequestBody DudyScheduleInitVO dudyScheduleInitVO) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitZS(dudyScheduleInitVO));
    }

    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化-第一步", notes = "排班分配初始化-第一步")
    @PostMapping("/dutyScheduleInitStep1")
    public BaseResult<List<DutyPersonInitDetailVO>> dutyScheduleInitStep1(@RequestBody DudyScheduleInitVO dudyScheduleInitVO) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitStep1(dudyScheduleInitVO));
    }
    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化-第一步-总署", notes = "排班分配初始化-第一步-总署")
    @PostMapping("/dutyScheduleInitStep1ZS")
    public BaseResult<List<DutyPersonInitDetailVO>> dutyScheduleInitStep1ZS(@RequestBody DudyScheduleInitVO dudyScheduleInitVO) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitStep1ZS(dudyScheduleInitVO));
    }

    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化-获取属于指定类型的人员")
    @PostMapping("/dutyScheduleInitPerson")
    public BaseResult<List<BasePersonInfoInitVO>> dutyScheduleInitPerson(@RequestParam("customId") String customId,
                                                                         @RequestParam("seType") String seType) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitPerson(customId,seType));
    }


    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班分配初始化-获取属于指定类型的人员")
    @PostMapping("/dutyScheduleInitPersonZS")
    public BaseResult<List<BasePersonInfoInitVO>> dutyScheduleInitPersonZS(@RequestParam("customId") String  type) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitPersonZS(type));
    }

    /**
     * 排班分配初始化
     * @return
     */
    @ApiOperation(value = "排班人员选择初始化-获取属于指定类型的人员")
    @PostMapping("/dutyScheduleInitPersonForDetail")
    public BaseResult<BasePersonInfoInitVO> dutyScheduleInitPersonForDetail(@RequestBody DutyScheduleInitPersonForDetailDTO dutyScheduleInitPersonForDetailDTO) throws Exception {
        return BaseResult.ok(baseDeptInfoService.dutyScheduleInitPersonForDetail(dutyScheduleInitPersonForDetailDTO.getCustomId(),dutyScheduleInitPersonForDetailDTO.getSeType(),dutyScheduleInitPersonForDetailDTO.getDutyType()));
    }
    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "部门下人员查询", notes = "部门下人员查询")
    @GetMapping("/userInDept")
    public BaseResult userInDept(@RequestParam("deptId") String deptId) {
        return BaseResult.ok(baseDeptInfoService.userInDept(deptId));
    }

    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区下人员查询", notes = "关区下人员查询")
    @GetMapping("/userInCustoms")
    public BaseResult userInCustoms(@RequestParam("customsId") String customsId) throws Exception {
        return BaseResult.ok(baseDeptInfoService.userInCustoms(customsId));
    }



    /**
     * 分页查询
     * @return
     */
    @ApiOperation(value = "关区下人员查询", notes = "关区下人员查询")
    @GetMapping("/userWithPromission")
    public BaseResult userWithPromission(@RequestParam("customsId") String customsId ,
                                         @RequestParam(value = "userName" ,required = false) String userName) throws Exception {
        UserInfoDetailVO userInfoDetailVO=loginCompoentService.getUserInfo();
        return BaseResult.ok(baseDeptInfoService.userWithPromission(customsId,userInfoDetailVO,userName));
    }

    @ApiOperation(value = "获取父级部门id列表", notes = "获取父级部门id列表")
    @GetMapping("/getDeptIdList")
    public BaseResult<List<String>> getDeptIdList(@RequestParam("deptId") String deptId) {
        List<String> ids=new ArrayList<>();
        baseDeptInfoService.setPubDepList(deptId,ids);
        if (ids.size()>0){
            ids.remove(0);
        }
        return BaseResult.ok(ids);
    }

}
